package core1;

import processing.core.PApplet;

public class PanZoom {
	
	private PApplet parent;

	public PanZoom(PApplet parent) {
		super();
		this.parent = parent;
	}
	
	float scaleUp = 0.5f;
	float wheel = 1.0f;
	float wheelMult =0.10f;
	float x;
	float y;
	float xOffset;
	float yOffset;
	float xold;
	float yold;
	float xpiv;
	float xpivOld;
	float ypiv;
	float ypivOld;

	
	
	public void transScale(float x, float y, float scale) {
		  if (parent.mousePressed == true) {
		  xOffset = x-xold;
		  yOffset = y-yold;
		  xpiv = (xpivOld-xOffset/scaleUp);
		  ypiv = (ypivOld-yOffset/scaleUp);
		  xpiv = xpiv + (xOffset/scaleUp);
		  ypiv = ypiv + (yOffset/scaleUp);
		  xpivOld = xpiv;
		  ypivOld = ypiv;
		  xold = x;
		  yold = y;
		  }
		  else{
	      xOffset = x-xold;
		  yOffset = y-yold;
		  xpiv = (xpivOld-xOffset/scaleUp);
		  xpivOld = xpiv;
		  ypiv = (ypivOld-yOffset/scaleUp);
		  ypivOld = ypiv;
		  xold = x;
		  yold = y;
		  }   
		  // blue grid position
		 // parent.translate(x, y);
		  parent.scale(scale);
		 

		  // negate mouse position
		  parent.translate(xpiv, ypiv);

		}

	

}
